/**
 * HR 月评
 */
import React from 'react';
import { Collapse } from '@/molecules';
import { useCollapse } from '@/hooks';
import { Attendance, DetailDiscussArrange, AssessHRDetail, AssessTask, AssessAbilityResult } from '../containers';
import { useAssessSetting } from '../hooks';
import { TRIAL_ACTION } from '../constants';

const { Panel } = Collapse;

function AssessHRW({ data = {} }) {
    const { activeKey, onChange } = useCollapse(['1', '2', '3', '4', '5'], []);
    const { assessWeekly } = data;
    const { w } = useAssessSetting(data);

    const hrDetail = React.useMemo(() => assessWeekly.find(item => item.status === TRIAL_ACTION.ASSESS_HR_WEEK), []);
    const assessDetail = React.useMemo(
        () => assessWeekly.filter(item => item.status !== TRIAL_ACTION.ASSESS_HR_WEEK),
        []
    );

    // 人事评价 evaluationType 0:不合格 1:合格 2:需观察
    const showDiscuss = React.useMemo(() => ['0', '2'].includes(hrDetail?.evaluationType), [hrDetail]);

    return (
        <div>
            <Collapse bordered={false} activeKey={activeKey} onChange={onChange}>
                {w.showTask && (
                    <Panel header="任务情况" key="1">
                        <AssessTask data={data} />
                    </Panel>
                )}
                {w.showAssess && (
                    <Panel header="能力评估" key="2">
                        <AssessAbilityResult
                            data={assessDetail}
                            levels={data?.assessAbility?.levels}
                            employeeCode={data?.employeeCode}
                        />
                    </Panel>
                )}
                <Panel header="考勤情况" key="3">
                    <Attendance data={data} type="week" />
                </Panel>
                <Panel header="人事评估意见" key="4">
                    <AssessHRDetail data={hrDetail} />
                </Panel>
                {showDiscuss && (
                    <Panel header="新员工面谈安排" key="5">
                        <DetailDiscussArrange data={hrDetail?.interviewArrange} />
                    </Panel>
                )}
            </Collapse>
        </div>
    );
}

export default AssessHRW;
